package net.easyjava.test.bean;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import net.easyjava.third.db.annotation.Column;
import net.easyjava.third.db.annotation.ID;
import net.easyjava.third.db.annotation.Table;
import net.easyjava.third.search.annotation.Index;
import net.easyjava.third.search.annotation.IndexID;
import net.easyjava.tools.BaseBean;


/**
 * Created by wxnacy on 16/6/23.
 */
@Table("METRO")
@Index(index = "test-metro",type="metro")
public class MetroBean extends BaseBean implements Comparable<MetroBean>  {
    private static final long serialVersionUID = -82766438995340783L;
    @ID(autoIncrement = true)
    @Column(value = "id",length = 20)
    @IndexID
    private long stationId;
    @Column(value = "station_name",length = 32)
    private String stationName;
    @Column(value = "line_ids",length = 64)
    private String lineIds;
    @Column(length = 32)
    private String lat;
    @Column(length = 32)
    private String lng;
    @Column(value = "build_time",length = 20,defaultValue = "0")
    private Long buildTime;
    @Column(value = "update_time",length = 20,defaultValue = "0")
    @JSONField(deserialize = false)
    private long updateTime;

    public MetroBean() {
    }

    public MetroBean(long stationId, String stationName) {
        this.stationId = stationId;
        this.stationName = stationName;
    }


    public long getStationId() {
        return stationId;
    }

    public void setStationId(long stationId) {
        this.stationId = stationId;
    }

    public String getStationName() {
        return stationName;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public String getLineIds() {
        return lineIds;
    }

    public void setLineIds(String lineIds) {
        this.lineIds = lineIds;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng;
    }

    public long getBuildTime() {
        return buildTime;
    }

    public void setBuildTime(long buildTime) {
        this.buildTime = buildTime;
    }

    public long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     * <p/>
     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
     * <tt>y.compareTo(x)</tt> throws an exception.)
     * <p/>
     * <p>The implementor must also ensure that the relation is transitive:
     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
     * <tt>x.compareTo(z)&gt;0</tt>.
     * <p/>
     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
     * all <tt>z</tt>.
     * <p/>
     * <p>It is strongly recommended, but <i>not</i> strictly required that
     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
     * class that implements the <tt>Comparable</tt> interface and violates
     * this condition should clearly indicate this fact.  The recommended
     * language is "Note: this class has a natural ordering that is
     * inconsistent with equals."
     * <p/>
     * <p>In the foregoing description, the notation
     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
     * <i>expression</i> is negative, zero or positive.
     *
     * @param o the object to be compared.
     * @return a negative integer, zero, or a positive integer as this object
     * is less than, equal to, or greater than the specified object.
     * @throws NullPointerException if the specified object is null
     * @throws ClassCastException   if the specified object's type prevents it
     *                              from being compared to this object.
     */
    @Override
    public int compareTo(MetroBean o) {
        if(o.getStationId()<this.getStationId()){
            return 1;
        }
        if(o.getStationId()==this.getStationId()){
            return 0;
        }

        return -1;
    }


    public static void main(String[] args) {
        MetroBean metroBean = new MetroBean();
        metroBean.setUpdateTime(System.currentTimeMillis());
        String json = JSONObject.toJSONString(metroBean);
        System.out.println("JSONObject.toJSONString(metroBean) = " + json);
        System.out.println("JSONObject.parseObject(json,MetroBean.class) = " + JSONObject.parseObject(json, MetroBean.class));
    }
}
